﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace WebAppUploader
{
	public class PasswordTextBox : Border
	{
		PasswordBox box = new PasswordBox();

		public PasswordTextBox()
		{
			this.Child = box;
			box.PasswordChanged += new RoutedEventHandler(box_PasswordChanged);
		}

		#region void  box_PasswordChanged(object sender, RoutedEventArgs e)
		void box_PasswordChanged(object sender, RoutedEventArgs e)
		{
			if(this.Password!=box.Password)
				this.Password = box.Password;			
		}
		#endregion


		///<summary>
		///DependencyProperty Password
		///</summary>
		#region Dependency Property Password
		public string Password
		{
			get { return (string)GetValue(PasswordProperty); }
			set { SetValue(PasswordProperty, value); }
		}

		///<summary>
		/// Using a DependencyProperty as the backing store for Password.  This enables animation, styling, binding, etc...
		///</summary>
		public static readonly DependencyProperty PasswordProperty =
			DependencyProperty.Register("Password", typeof(string), typeof(PasswordTextBox), new FrameworkPropertyMetadata("", OnPasswordChangedCallback));

		private static void OnPasswordChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			PasswordTextBox obj = d as PasswordTextBox;
			if (obj != null)
			{
				obj.OnPasswordChanged(e);
			}
		}

		/// <summary>
		/// Fires PasswordChanged event.
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnPasswordChanged(DependencyPropertyChangedEventArgs e)
		{
			if (PasswordChanged != null)
			{
				PasswordChanged(this, EventArgs.Empty);
			}
			if (box.Password != this.Password)
				box.Password = this.Password;
		}

		///<summary>
		///
		///</summary>
		public event EventHandler PasswordChanged;

		#endregion


	}
}
